import SparkMD5 from 'spark-md5';

/** 计算文件加密标识 */
function computeMD5(file) {
  return new Promise((resolve, reject) => {
    var spark = new SparkMD5.ArrayBuffer();
    var fileReader = new FileReader();
    fileReader.readAsArrayBuffer( file.slice(0, .5 * 1024 * 1024) );
    fileReader.onload = event => {
      spark.append(fileReader.result)
      file.uniqueIdentifier = spark.end()
    }

    fileReader.onloadend = () => { resolve(file) }
  })
}

export { computeMD5 };
